package com.chen.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.bean.Category;
import com.chen.common.R;
import com.chen.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/category")
@RestController
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 新增分类
     * @param category
     * @return
     */
    @PostMapping
    public R<String> addCategory(@RequestBody Category category){
        return categoryService.addCategory(category);
    }

    /**
     * 菜品分类 分页查询
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public R<Page<Category>> CategoryPage(Integer page,Integer pageSize){
        return categoryService.CategoryPage(page,pageSize);
    }

    /**
     * 修改菜品分类
     * @param category
     * @return
     */
    @PutMapping
    public R<String> updateCategory(@RequestBody Category category){
        return categoryService.updateCategory(category);
    }

    /**
     * 删除菜品分类
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public R<String> deleteCategory(@PathVariable Long ids){
        return categoryService.deleteCategory(ids);
    }

    /**
     * 查询所有菜品分类
     * @param type
     * @return
     */
    @GetMapping("/list")
    public R<List<Category>> categoryList(Integer type){
        return categoryService.categoryList(type);
    }
}
